let mongoose = require("mongoose");

mongoose.connect("mongodb://127.0.0.1:27017/blog");

let Schema = mongoose.Schema;

let userSchema = new Schema(
  {
    username: String,
    password: String,
  },
  {
    timestamps: true,
  }
);

let User = mongoose.model("User", userSchema);

let ArticleSchema = new Schema(
  {
    title: String,
    content: String,
    author: { type: Schema.Types.ObjectId, ref: "User" },
  },
  {
    timestamps: true,
  }
);

let Article = mongoose.model("Article", ArticleSchema);

let CommentSchema = new Schema(
  {
    content: String,
    reply_user_id: { type: Schema.Types.ObjectId, ref: "User" },
    article_id: { type: Schema.Types.ObjectId },
  },
  {
    timestamps: true,
  }
);

let Comment = mongoose.model("Comment", CommentSchema);

module.exports = { Comment, Article, User };
